package com.espressif.espblufi.ui;

import android.annotation.SuppressLint;
import android.bluetooth.BluetoothDevice;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.SystemClock;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;

import com.espressif.espblufi.R;
import com.espressif.espblufi.callback.IConnectDevice;
import com.espressif.espblufi.constants.BlufiConstants;

import blufi.espressif.BlufiClient;

/**
 * =============================================================
 * <p/>
 * Copyright  : Personal Creation All (c) 2018
 * <p/>
 * Author      : Heaven
 * <p/>
 * Version     : 1.0
 * Date of creation : 2018/12/24 10:13.
 * <p/>
 * Description  :
 * <p/>
 * <p/>
 * Revision history :
 * <p/>
 * =============================================================
 */
public class ConnectDevice extends AppCompatActivity implements IConnectDevice {

    private ImageView mImgBack = null;
    private BluetoothDevice mDevice = null;
    private BlufiActivity mBlufiActivity;
    private BlufiClient mBlufiClient;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.connect_activity);
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.hide();
        }
        initView();
        initConnect();
//        initSecureConnect(mBlufiClient);
//        makeDeviceGroup(mBlufiClient);
    }


    private void initView() {
        mImgBack = findViewById(R.id.iv_back);
        mImgBack.setOnClickListener(new ImageBack());
    }

    private void initConnect() {
        mDevice = getIntent().getParcelableExtra(BlufiConstants.KEY_BLE_DEVICE);
//        mBlufiActivity = new BlufiActivity(this);
//        mBlufiActivity.initView(mDevice,this);
//        mBlufiActivity.connectBluDevice(mDevice);
    }

//    private void initSecureConnect(BlufiClient mBlufiClient) {
//        mBlufiActivity.negotiateSecurity(mBlufiClient);
//    }

    private void makeDeviceGroup(BlufiClient mBlufiClient) {
        String str = "ssssssssss";
//        mBlufiActivity.makeDeviceGroup(mBlufiClient,str);
//        mBlufiActivity.postCustomData(ConnectDevice.this);
    }

    private void justifyGroup() {

    }

    @Override
    public void setData(BlufiClient mBlufiClient) {
        this.mBlufiClient = mBlufiClient;
//        ConnectDevice.this.runOnUiThread(new Runnable() {
//            @Override
//            public void run() {
//
//            }
//        });

//        initSecureConnect(mBlufiClient);
//        makeDeviceGroup(mBlufiClient);

    }

    private class ImageBack implements View.OnClickListener {
        @Override
        public void onClick(View view) {
            switch (view.getId()) {
                case R.id.iv_back:
                    finish();
                    break;
//                case R.id.bt_next_connect:
//                    startActivity(new Intent(BlueWifiSetting.this, ConnectDevice.class));
//                    break;
            }

        }
    }
}
